<?php

namespace app\admin\validate;

use think\Db;
use think\Validate;

class Allot extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'buser_id'   => 'require',
        'admin_id'   => 'require',
        'product_id' => 'require|unique:allot,buser_id^admin_id',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'buers_id.require'   => '客户必须',
        'admin_id.require'   => '负责人必须',
        'product_id.require' => '推荐产品必须',
        'product_id.unique'  => '您已有对应的线索，请勿重复添加',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];

    //检查是否已有对应的产品线索
    function check_unique($value,$rule,$data)
    {
        $find=Db::name('allot')->where([
            'buser_id'   => $data['buser_id'],
            'admin_id'   => $data['admin_id'],
            'product_id' => $data['product_id']
        ])->find();
        if($find)
            return '您已有对应的线索，请勿重复添加';
        else
        {
            return true;
        }
    }
    
}
